package org.aliwo.lamda;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * .
 *
 * @author Xu Yayuan
 * @date 2021/12/3
 */
public class Testfilter {
    public static void main(String[] args) {

        Student s1 = new Student(11, "black", 456);
        Student s2 = new Student(12, "red", 123);//old

        Student s3 = new Student(11, "black", 123);
        Student s4 = new Student(12, "red1", 123);
        Student s5 = new Student(15, "white", 123);//new

        List<Student> oldList = new ArrayList<Student>() {{
            add(s1);
            add(s2);
        }};
        List<Integer> oldAgeList = oldList.stream().map(x -> x.getAge()).collect(Collectors.toList());

        List<Student> newList = new ArrayList<Student>() {{
            add(s3);
            add(s4);
            add(s5);
        }};
        List<Integer> newAgeList = oldList.stream().map(x -> x.getAge()).collect(Collectors.toList());

        //List<Bean> 根据Bean的一个属性求两个list的交集 差集
        //交集
        // List<Student> updList = oldList.stream()
        //         .filter(item -> newList.stream()
        //                 .map(e -> e.getAge())
        //                 .collect(Collectors.toList())
        //                 .contains(item.getAge()))
        //         .collect(Collectors.toList());
        // System.out.println(updList);

        // 差集 (new - old)
        List<Student> addList = newList.stream()
                .filter(item -> !oldList.stream()
                        .map(e -> e.getAge() )
                        .collect(Collectors.toList())
                        .contains(item.getAge()))
                .collect(Collectors.toList());
        System.out.println(addList);

        // 差集 (old - new)
        // List<Student> delList = oldList.stream()
        //         .filter(item -> !newList.stream()
        //                 .map(e -> e.getAge() )
        //                 .collect(Collectors.toList())
        //                 .contains(item.getAge()))
        //         .collect(Collectors.toList());
        // System.out.println(delList);

        //List<Bean> 根据Bean的2个属性求两个list的交集 差集？？

    }
}
